#!/usr/bin/env python

"""Builds a current version of the library with Dojo Shrinksafe."""

__author__ = "Igor Kulkin <igor.kulkin@gmail.com>"

import glob
import os
import os.path

SOURCE_PATH = 'src'
TARGET_FILE = 'opt/geo-polygon-utils.js'

target_dir = os.path.dirname(TARGET_FILE)

# Cleaning up.
if os.path.exists(target_dir):
  if os.path.isdir(target_dir):
    if os.path.exists(TARGET_FILE):
      os.remove(TARGET_FILE)
    os.rmdir(target_dir)
  else:
    os.remove(target_dir)

# Creating target directory.
os.mkdir(target_dir)

source_files = glob.glob(os.path.join(SOURCE_PATH, '*'))
os.system('java -jar tools/shrinksafe/shrinksafe.jar %s > %s' %
          (' '.join(source_files), TARGET_FILE))
